//
//  STSettingController.swift
//  iPhone
//
//  Created by Toj on 5/26/22.
//

import UIKit
import TTCOM_iOS

class STSettingController: STBaseViewController {
    
    override var pagePath: String {
        return "startimes://me/settings"
    }
    
    private lazy var subvc: UIViewController = {
        let vc = UIViewController()
        vc.view.backgroundColor = .random
        return vc
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.title = "Me"
        
        tt_isNavigationBarHidden = true
        let height = 300.ui_scale
        let y = CGFloat.dv_height - height
        addChild(subvc)
        view.addSubview(subvc.view)
        subvc.view.frame = CGRect(x: 0, y: y, width: .sr_width, height: height)
        
        view.addSubview(settingButton)
        settingButton.frame = CGRect(x: 50, y: 100, width: 100, height: 100)
        
        view.addSubview(settingButton2)
        settingButton2.frame = CGRect(x: 100, y: 300, width: 100, height: 100)
        
        view.addSubview(settingButton3)
        settingButton3.frame = CGRect(x: 250, y: 100, width: 100, height: 100)
    }
    
    @objc private func didTapSetting3() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            self.alertMore1()
        }
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            self.alertMore2()
        }
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            self.alertMore3()
        }

        DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
            self.alertMore4()
        }
    }
    
    @objc private func didTapSetting2() {
        let _ =  UIViewController.vc_currentNavigationTopViewController
        
        // print("-->toj: \(vc)")
        
        let _ = vc_isTopViewController
        // print("-->toj: \(isTop)")
        
        // navigationController?.pushViewController(TestViewController(), animated: true)
    }
    
    @objc private func didTapSetting() {
        let vc = TVLinkingCardViewController()
        UIViewController.vc_currentNavigation?.pushViewController(vc, animated: true)
    }
    
    func alertMore1() {
        var model = STAlertModel()
        model.title = "Alert 1"
        model.popDescription = "桌上的坚果开心果5"
        model.topPicUrl = "http://vip.meisupic.com/goods/goods.php?a=1156252"
        model.popUrl = "http://vip.meisupic.com/goods/goods.php?a=1156282"
        STAlertHelper.manager.show(alerModel: model) {
            let vc = STSettingController()
            UIViewController.vc_currentNavigation?.pushViewController(vc, animated: true)
            // print("-->toj: default1 action")
        } cancelAction: {
            // print("-->toj: cancel1 action")
        } effectAction: {
            // print("-->toj: effect1 action")
        }
    }
    
    func alertMore2() {
        var model = STAlertModel()
        model.title = "Alert 2"
        model.popDescription = "盘中的香酥椒1"
        model.topPicUrl = "http://vip.meisupic.com/goods/goods.php?a=1156273"
        model.popUrl = "http://vip.meisupic.com/goods/goods.php?a=1156263"
        STAlertHelper.manager.show(alerModel: model) {
            let vc = TVLinkingCardViewController()
            UIViewController.vc_currentNavigation?.pushViewController(vc, animated: true)
            // print("-->toj: default2 action")
        } cancelAction: {
            // print("-->toj: cancel2 action")
        } effectAction: {
            // print("-->toj: effect2 action")
        }
    }
    
    func alertMore3() {
        var model = STAlertModel()
        model.title = "Alert 3"
        model.topPicUrl = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi.qqkou.com%2Fi%2F0a3555809371x1438535940b26.jpg&refer=http%3A%2F%2Fi.qqkou.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665802388&t=baa31eb1d81af34f3e884e8a590efe04"
        model.popUrl = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.duoziwang.com%2F2017%2F04%2F29%2FB7936.jpg&refer=http%3A%2F%2Fimg.duoziwang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665802396&t=3457aa185045c0c5ceabe1f767937b3e"
        STAlertHelper.manager.show(alerModel: model) {
            UIViewController.vc_currentNavigation?.popViewController(animated: true)
            // print("-->toj: default3 action")
            self.alertMore4()
        } cancelAction: {
            // print("-->toj: cancel3 action")
        } effectAction: {
            // print("-->toj: effect3 action")
        }
    }
    
    func alertMore4() {
        var model = STAlertModel()
        model.title = "Alert 4"
        model.popDescription = "拔丝山楂的做法材料:新鲜山楂12个、白砂糖120克、纯净水35克步骤1、将白砂糖倒入不粘小奶锅中称好。2、水称好3、山楂去蒂洗净用厨房纸搽干水份备用。"
        model.topPicUrl = "http://www.4493.com/meishi/50956/1.htm"
        model.popUrl = "http://www.4493.com/meishi/30508/1.htm"
        STAlertHelper.manager.show(alerModel: model) {
            // print("-->toj: default4 action")
        } cancelAction: {
            // print("-->toj: cancel4 action")
        } effectAction: {
            // print("-->toj: effect4 action")
        } 
    }
    
    private lazy var settingButton: UIButton = {
        let view = UIButton()
        view.setTitle("Setting", for: .normal)
        view.backgroundColor = .random
        view.addTarget(self, action: #selector(didTapSetting), for: .touchUpInside)
        return view
    }()
    
    private lazy var settingButton2: UIButton = {
        let view = UIButton()
        view.setTitle("Setting2", for: .normal)
        view.backgroundColor = .random
        view.addTarget(self, action: #selector(didTapSetting2), for: .touchUpInside)
        return view
    }()
    
    private lazy var settingButton3: UIButton = {
        let view = UIButton()
        view.setTitle("Setting3", for: .normal)
        view.backgroundColor = .random
        view.addTarget(self, action: #selector(didTapSetting3), for: .touchUpInside)
        return view
    }()
}
